package com.jbh.module_login

import android.os.Bundle
import android.util.Log
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
import androidx.activity.ComponentActivity
import com.alibaba.android.arouter.facade.annotation.Route
import com.google.gson.Gson
import com.jbh.lib_base.RoutePath
import com.jbh.request.AppApi.AppImpl
import com.jbh.request.i.YxjCallback

@Route(path = RoutePath.Login_Activity)
class LoginActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_login)
        findViewById<TextView>(R.id.btnLogin).setOnClickListener {
            val edUserName = findViewById<EditText>(R.id.edUserName).text.toString()
            val edPwd = findViewById<EditText>(R.id.edPwd).text.toString()
            login(edUserName,edPwd)
        }
    }


    private fun login(name:String,pwd:String) {
        AppImpl.Login(name, pwd, object : YxjCallback<Any>() {
            override fun onSuccess(t: Any) {
                showLog("[Login]=${Gson().toJson(t)}")
                runOnUiThread {
                    Toast.makeText(this@LoginActivity,"登录成功！",Toast.LENGTH_LONG).show()
                }
            }
            override fun onFailure(code: Int, msg: Any) {
                showLog(msg.toString())
                runOnUiThread {
                    Toast.makeText(this@LoginActivity,"登录成功！",Toast.LENGTH_LONG).show()
                }
            }
        })
    }


    private fun showLog(msg: String) {
        Log.v("[showLog]->", msg)
    }
}